﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections;
using System.ComponentModel;
using System.Text.RegularExpressions;
using TA.JSON;
using System.IO;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Reflection;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Entries load event arguments.
	/// </summary>
	public class RepeaterEntriesEventArgs : EventArgs, IJsonDeserializable, IJsonSerializable
	{
		//public RepeaterEntriesEventArgs(int firstRow, int numRows)
		//{
		//  this.Entries = new RepeaterEntries();
		//  this._firstRow = firstRow;
		//  this._numRows = numRows;
		//}
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		/// <param name="owner"></param>
		/// <param name="jr"></param>
		public RepeaterEntriesEventArgs(Repeater owner, JsonReader jr)
			: this(owner)
		{
			this.DeserializeObject(jr);
		}
		/// <summary>
		/// Ctor.
		/// </summary>
		/// <param name="owner"></param>
		/// <param name="firstRow"></param>
		/// <param name="numRows"></param>
		public RepeaterEntriesEventArgs(Repeater owner, int firstRow, int numRows)
			: this(owner)
		{
			this.FirstRow = firstRow;
			this._numRows = numRows;
		}
		RepeaterEntriesEventArgs(Repeater owner)
		{
			this._repeater = owner;
		}
		#endregion
		#region PROPS
		/// <summary>
		/// Gets the first row to retrieve, or sets the first row that was retrieved.
		/// </summary>
		public int FirstRow { get; set; }
		/// <summary>
		/// Gets the number of rows after <see cref="FirstRow"/> needed for this request.
		/// </summary>
		public int NumRows { get { return this._numRows; } }
		/// <summary>
		/// Collection of entries to be returned to the caller.
		/// </summary>
		public IRepeaterEntries Entries
		{
			get
			{
				return this._entries;
			}
			set
			{
				this._entries = value;
				this._entries.Repeater = this._repeater;
			}
		}
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		int _numRows;
		IRepeaterEntries _entries;
		Repeater _repeater;
		#endregion
		#region METHODS
		#region IJsonDeserializable Members
		/// <summary>
		/// Deserialize.
		/// </summary>
		/// <param name="jr"></param>
		public void Deserialize(IJsonReader jr)
		{
			this.DeserializeObject(jr);
		}
		/// <summary>
		/// DeserializeContent.
		/// </summary>
		/// <param name="jr"></param>
		/// <param name="propShortName"></param>
		public void DeserializeContent(IJsonReader jr, string propShortName)
		{
			switch (propShortName)
			{
				case "F": this.FirstRow = (int)(long)jr.Value; break;
				case "N": this._numRows = (int)(long)jr.Value; break;
			}
		}
		#endregion
		#region IJsonSerializable Members
		/// <summary>
		/// IsDirty.
		/// </summary>
		public bool IsDirty
		{
			get { return true; }
		}
		/// <summary>
		/// Serialize.
		/// </summary>
		/// <param name="jw"></param>
		public void Serialize(JsonWriter jw)
		{
			this.SerializeObject(jw);
		}
		/// <summary>
		/// SerializeContents.
		/// </summary>
		/// <param name="jw"></param>
		public void SerializeContents(JsonWriter jw)
		{
			jw.PropertyName("F");
			jw.Value(this.FirstRow);

			jw.PropertyName("E");
			jw.Value(this.Entries);
		}

		#endregion
		#endregion
		#endregion
	}
}